# coding=utf-8

# @Time : 2019/12/15 15:14
# @Author : zhusc
# @File : logic/assis_logic.py
# @Desc : 助理号数据相关处理

class AssistantLogic:
    def get_assistant_everyday_sale_info(self, mysql, assistant_id, ts_s, ts_e):
        """ 获取助理每日下单情况
        """
        sql_sale_info = "\
        SELECT \
            id, \
            sp_id, \
            num, \
            totle \
        FROM \
            ko_order \
        WHERE \
            sale_mid = %d \
        AND cw_date >= '%s' \
        AND cw_date <= '%s' \
        AND `status` IN (4, 5, 6, 9, 10, 11, 12) \
        AND tui_status <> 3 \
        " % (assistant_id, ts_s, ts_e)
        sale_res = mysql.select(sql_sale_info)
        return sale_res

    def cal_sale_num_amount(self, assistant_sale_info):
        """ 根据查询结果计算商品当日的售出数量和售出金额
        """
        sale_info_return = {
            'sale_num': 0, 
            'sale_amount': 0.00
        }
        for info in assistant_sale_info:
            sale_info_return['sale_num'] += info['num']
            sale_info_return['sale_amount'] += info['totle']
        return sale_info_return
